import QtQuick 1.1
import org.kde.plasma.core 0.1 as PlasmaCore
import org.kde.plasma.components 0.1 as PlasmaComponents
import "../code/task.js" as TaskFunctions

Content {
    id:  buttonsContent
    
    property string source
    property bool maximizedWindow
    property alias spacing: buttonsItem.spacing
    property int minimumButtonsSize
    
    property int visiblesButtons: 2 // TODO: implement counting
    
    minimumWidth:  width>height?visiblesButtons*minimumButtonsSize+(visiblesButtons-1)*spacing: minimumButtonsSize
    minimumHeight: width>height?minimumButtonsSize:visiblesButtons*minimumButtonsSize+(visiblesButtons-1)*spacing
        
    PlasmaCore.Svg {
        id: controlsSvg
        imagePath: "widgets/configuration-icons"
    }
    
    Grid {
        id: buttonsItem
        
        rows: width>height?1:buttonsContent.visiblesButtons
        columns: width>height?buttonsContent.visiblesButtons:1
        
        anchors.fill:parent
        ButtonContent {
            id: closeButton
            
            svg: controlsSvg
            name: "close"
            show: false
            minimumWidth: buttonsContent.minimumButtonsSize
            minimumHeight: buttonsContent.minimumButtonsSize
            
            onClicked: TaskFunctions.close(buttonsContent.source)
            
            width:Math.min(parent.width-(parent.spacing*(parent.columns-1))/parent.columns, desiredWidth)
            height: Math.min(parent.height-(parent.spacing*(parent.rows-1))/parent.rows, desiredHeight)
            
        }

        ButtonContent {
            id: toggleMaximizedButton
            
            svg: controlsSvg
            name: buttonsContent.maximizedWindow?"unmaximize":"maximize"
            show: false
            minimumWidth: buttonsContent.minimumButtonsSize
            minimumHeight: buttonsContent.minimumButtonsSize
            
            onClicked: TaskFunctions.toggleMaximized(buttonsContent.source)
            
            width:Math.min(parent.width-(parent.spacing*(parent.columns-1))/parent.columns, desiredWidth)
            height: Math.min(parent.height-(parent.spacing*(parent.rows-1))/parent.rows, desiredHeight)
            
        }
    }        
}
